package TcpUdpDemp;

import java.io.*;
import java.net.*;

public class aa {
    public static void main(String[] args) {
        int port = 1234; // 定义服务端端口
        try (ServerSocket serverSocket = new ServerSocket(port);
             Socket socket = serverSocket.accept();
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
             BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {

            System.out.println("Client connected");

            String fromClient = in.readLine(); // 读取客户端发送的消息
            System.out.println("Client says: " + fromClient);

            String response = "你好，我现在有事不在，请稍后联系"; // 服务端的自动回复
            out.println(response); // 发送回复到客户端

            String fromUser = stdIn.readLine(); // 服务端用户输入
            if ("bye".equalsIgnoreCase(fromUser)) {
                System.out.println("Server is shutting down");
                socket.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}